package org.maruero.client;

import java.util.List;
import java.util.Properties;

import javax.naming.InitialContext;

import org.maruero.ejb.entity.Book;
import org.maruero.ejb.inter.Books;

public class BookStoreClient {

	protected void listBook() {
		try{
		
			Properties p = new Properties();
    		p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    		p.put("java.naming.provider.url", "http://127.0.0.1:8080/openejb/ejb");
    		InitialContext context = new InitialContext( p ); 
    		
	        Books books = (Books)context.lookup("BookssRemote");
	        books.load();
	        
	        List<Book> bookList = books.getBooks();
	        
	        for( Book book : bookList ){
	        	System.out.println("--------------------------");
	        	System.out.println("Title: " + book.getTitle() );
	        	System.out.println("Author: " + book.getAuthor() );
	        	System.out.println("Year: " + book.getYear() );
	        }
	        
        
		}catch( Exception e ){
			System.out.println("Exception caught: " + e.getMessage() );
		}
	}
	
	public static void main(String[] args ){
		new BookStoreClient().listBook();
	}

}
